Release 10.1A: OpenEdge Getting Started:
Object-oriented Programming
Defining an object reference as a field in a temp-table
Temp-tables can define classes as fields. Classes are always represented by value, that is, the value of the object reference, not the object itself. You define a class field in a temp-table as a
Progress.Lang.Object, the built-in class that is the implicit super class (root class) of all user-defined classes. When object instances are assigned to the field, they are implicitly cast to the root class,Progress.Lang.Object. When you want to use the object reference as a specific class type, you must cast the object reference to the specific type. For more information on casting, see the "Assignment and the CAST function" section.As with class type parameters, a temp-table containing a class field cannot be passed to or from a remote application server.
This is the syntax to define a class field in a temp-table:
Element descriptions for this syntax diagram follow:
field-nameThe name of a field defined as the Progress root class.
Note: You cannot define a class field in an OpenEdge database table.The following example defines a temp-table field to hold a class instance, by defining the field as
Progress.Lang.Object. In this case, the purpose is to store differentShapeClassinstances in order to calculate an area on eachShapeClassobject in sequence, according to its subclass type (RectangleClassorCircleClass), as shown:
The previous example is based on the classes used to demonstrate polymorphism in a previous chapter (see the "Using polymorphism with classes" section). This version of the
Mainclass thus shows how you might use temp-table fields to support polymorphic object references and use theCASTfunction to cast down to the common functionality of the polymorphic super class (ShapeClass).
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |